addi $t0, $0, 0xC      # set address of isr
mtc0 $t0, $15          # set ebase

j start

isr: mfc0 $k0, $13     # load the cause register
andi $k0, $k0, 0x8000  # check that it is from the keypad (bit 15)
bne $k0, $0, keypad    # branch if it is the keypad
eret                   # otherwise eret, we aren't handling anything else

keypad: lw $a0, 0($s5) # read from the keypad
jal display            # display the buffer (display subroutine)
eret                   # return to program (loop)



display: lw $t0, 0($s1)# load switches
andi $t1, $a0, 0xFFFF  # get only latest four buttons
add $t1, $t1, $s3      # write values to the seven segs
sw $t1, 4($s2)         # write to seven segs
srlv $t0, $a0, $t0     # shift buffer by amount on switches
sw $t0, 0($s0)         # print out to leds
jr $ra

start:
lui $s0, 0xFFFF        # set offset for MMIO, and base address for leds
addi $s1, $s0, 0x0040  # set base address of the switches controller
addi $s5, $s0, 0x0140  # set base address of the hex keypad controller
addi $s2, $s0, 0x0080  # set base address for seven seg controller

addi $t0, $0, 0x000F   # turn all seven segs on
lui $s3, 0x00F0        # set mask for write enables and no dots
sw $t0, 0($s2)         # turn all seven segs on
sw $s3, 4($s2)         # write zeros without dots



ori $a0, $0, 0xAB00
ori $a0, $a0, 0x00CD



#mtc0 $0, $12




loop: j loop           # loop forever
